: GW Instek PSM-2010 power supply
; 
; Revision 1.0 	23 Apr 2020		Initial release

; ***************************** Design Notes *************************************
; *	The PSM-2010 is a dual-range device. The low range can provide               *
; * 8 Volts at 20 Amps, while the high range can provide 15 Volts                *
; * at 10 Amps.                                                                  *
; *                                                                              *
; * The device is initialized into the low range at start up. This               *
; * gives a known starting state, from which the user can then switch            *
; * to the high range and back. The current state is shown in the bottom         *
; * of the setup popup.                                                          *
; *                                                                              *
; * Note that the OVP and OCP limits do not change with the range selection.     *
; * So these parameters are placed in the bottom, or common, section of the      *
; * popup.                                                                       *
; *                                                                              *
; * The actual output voltage and current value limits do change with the        *
; * range, of course; they are thus put into separate tabs with appropriate      *
; * values for low and high ranges.                                              *
; ********************************************************************************

#author Hexley
#idString GW.Inc,PSM-2010, 
#name GWInstek PSM-2010
#handle PSM2010
#port COM

; A list of possible column name with unit and formatter (SI, Time, Int, D0..D6)

#value Voltage V D3 
#value Current A D3 



; How to poll for data, this is used for table and #values?
; a #askMode, #cmdMode and #prepareSample is used before this is string is used.
; This is a single line command
#askValues :MEAS?; *WAI; :MEAS:CURR?; 

; Format of answer: f=float, u=remove trailing letters, x=skip
#askValuesReadFormat 

; Accept this delay when reading values (seconds)
#readingDelay 5

; Mode change have a longer delay on reading values (seconds)
;#modeChangeDelay 10

; Switch meter to this mode during start, leave empty to avoid any switching
#initialMode

; String to ask about actual meter mode, 
; This is a single line command
#askMode 

; When one of these commands are used through the command interface a new configuration will be done before using #askMode
; Only one word for each #mayModifyMode
; Specify command without initial colon and in the shortest possible form
;#mayModifyMode 

; Prepare the meter to response to #askValues
#prepareSample

; Initial commands to meter when establishing connection
#initCmd  *CLS; :VOLT:RANG LOW; [*OPC];:VOLT 5.000; :CURR 1.000

; Final command to meter before breaking connection
#finalCmd *CLS; :SYST:LOC

#outputOff :OUTP:STAT 0

; Strings to configure device in different modes
; First parameter must match a #value (4 parameter) and second parameter must match what #askMode returns
; First parameter is also used in shortcut menu
;#cmdMode 


#interfaceType PS
#interface setVoltage :VOLT (value)
#interface setCurrent :CURR (value)
#interface setOn :OUTP:STAT (value)
#interface getVoltage :VOLT?
#interface getCurrent :CURR?
#interface getOn :OUTP:STAT?
#interface readVoltage 0 
#interface readCurrent 1


; ************************* Menu functions follow ***************************************
; Setup menu functions
; The parameters on the first line is: type name page 
; Settings on the following lines are:
; read: SCPI to read value from device, is used to synchronize when opening setup page or setting equal named fields. Not always used
; readformat: Parse read value.
; write: Send the value to device, this field is used in combination with data fields in the details to send updates to device.
; tip: Add this tip to all components for this input field.



; *******************************************************************
; *                         Output Low Range                        *
; *            Volts: 0 - 8          Amps: 0 - 20                   *
; *                                                                 *
; *******************************************************************

#cmdSetup radio Voltage Output_Low_Range_(P08V)
:read: [*OPC];:VOLT?; 
:readformat:
:write: :VOLT:RANG LOW; [*OPC];:VOLT #; :OUTP:STAT 1; [*OPC]
:update: Output Range
:tip: Setup this voltage, turn output on
3.3V 3.300
5V 5.000
8V 8.000


#cmdSetup radio Current Output_Low_Range_(P08V)
:read: :CURR?; 
:readFormat:
:write: :VOLT:RANG LOW; [*OPC]; :CURR #
:update: Range
:tip: Output will current limit at this current
500mA 0.5000
1A 1.000
5A 5.000
10A 10.000
20A 20.000

#cmdSetup buttonsOn Output Output_Low_Range_(P08V)
:read: :OUTP:STAT?; 
:write: :VOLT:RANG LOW; [*OPC]; :OUTP:STAT 
:update: Range
:tip: turn output on or off
:updatealloff:
Off 0
On 1

#cmdSetup number Voltage Output_Low_Range_(P08V)
:read: :VOLT? ; 
:readformat:
:write: :VOLT:RANG LOW; [*OPC]; :VOLT #
:update: Range
:tip: Setup this voltage, do not turn output on/off
Volt 0 8.24

#cmdSetup number Current Output_Low_Range_(P08V)
:read: :CURR? ; 
:readformat:
:write: :VOLT:RANG LOW; [*OPC]; :CURR #
:update: Range
:tip: Setup this current, do not turn output on/off
Amps 0.0 20.6



; *******************************************************************
; *                         Output High Range                       *
; *            Volts: 0 - 15          Amps: 0 - 10                  *
; *                                                                 *
; *******************************************************************

#cmdSetup radio Voltage Output_High_Range_(P20V)
:read: [*OPC];:VOLT?; 
:readformat:
:write: :VOLT:RANG HIGH; [*OPC]; :VOLT #; :OUTP:STAT 1; [*OPC]
:update: Output Range
:tip: Setup this voltage, turn output on
3.3V 3.300
5V 5.000
12V 12.000
15V 15.000

#cmdSetup radio Current Output_High_Range_(P20V)
:read: :CURR?; 
:readFormat:
:write: :VOLT:RANG HIGH; [*OPC]; :CURR #
:update: Range
:tip: Output will current limit at this current
200mA 0.200
500mA 0.500
1A 1.000
5A 5.000
10A 10.000


#cmdSetup buttonsOn Output Output_High_Range_(P20V)
:read: :OUTP:STAT?; 
:write: :VOLT:RANG HIGH; [*OPC]; :OUTP:STAT 
:tip: turn output on or off
:updatealloff:
:update: Range
Off 0
On 1

#cmdSetup number Voltage Output_High_Range_(P20V)
:read: :VOLT? ; 
:readformat:
:write: :VOLT:RANG HIGH; [*OPC]; :VOLT #
:update: Range
:tip: Setup this voltage, do not turn output on/off
Volt 0 20.6

#cmdSetup number Current Output_High_Range_(P20V)
:read: :CURR? ; 
:readformat:
:write: :VOLT:RANG HIGH; [*OPC]; :CURR #
:update: Range
:tip: Setup this current, do not turn output on/off
Amps 0.0 10.3



; *******************************************************************
; *                    COMMON CONTROLS                              *
; *******************************************************************

#cmdSetup info Range
:read: :VOLT:RANG?
;:readmath: substring(value,2);
:string:
_


#cmdSetup number OverVoltage
:read: :VOLT:PROT?; 
:write: :VOLT:PROT #; 
:tip: Set level of over voltage protection for Output
Volt 1 22

#cmdSetup number OverCurrent
:read: :CURR:PROT?; 
:write: :CURR:PROT #
:tip: Output will turn off if it is above this current
Amps 0.01 22

#cmdSetup number OCP_Delay
:read: :CURR:PROT:DEL?; 
:write: :CURR:PROT:DEL #
:tip: OCP trip delay
Sec 0 10

#cmdSetup checkbox Protection
:read: :VOLT:PROT:STAT?; 
:write: :VOLT:PROT:STAT #
:tip: Output overvoltage protection
:update: Status
OVP 0 1

#cmdSetup checkbox Protection
:read: :CURR:PROT:STAT?; 
:write: :CURR:PROT:STAT #
:tip: Output overcurrent protection
:update: Status
OCP 0 1

#cmdSetup checkbox Front_Panel_Display
:read: DISP? 
:write: DISP #
:tip: Turn on or off the front panel display
Visible 0 1

